package com.auth.manager.common.resp;

import java.io.Serializable;

/**
 * @version 1.0.0
 * @Date: 2022/4/27 14:46
 * @Author ZhuYouBin
 * @Description 统一响应结果
 */
public class Result implements Serializable {
    /***************************** member variable ******************************/
    // 状态码
    private Integer code;
    // 提示信息
    private String message;
    // 响应数据
    private Object data;

    /***************************** static method ******************************/

    public static Result success() {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMessage(ResultEnum.SUCCESS.getMessage());
        return result;
    }

    public static Result success(String message) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result success(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMessage(resultEnum.getMessage());
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMessage(ResultEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static Result failed() {
        Result result = new Result();
        result.setCode(ResultEnum.FAILED.getCode());
        result.setMessage(ResultEnum.FAILED.getMessage());
        return result;
    }

    public static Result failed(String message) {
        Result result = new Result();
        result.setCode(ResultEnum.FAILED.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result failed(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMessage(resultEnum.getMessage());
        return result;
    }

    /***************************** setter and getter ******************************/
    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Object getData() {
        return data;
    }
    public Result setData(Object data) {
        this.data = data;
        return this;
    }
}
